package org.example.struct.array;

/**
 * @author liyishan
 * @date 2024/8/8 09:12
 * @apiNote
 */

public class Test00661ImageSmoother {
    public int[][] imageSmoother(int[][] img) {
        int m = img.length;
        int n = img[0].length;
        int[][] result = new int[m][n];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                int left = Math.max(0,i-1);
                int right = Math.min(m-1,i+1);
                int top = Math.max(0,j-1);
                int bottom = Math.min(n-1,j+1);
                int count = 0;
                int sum = 0;
                for(int x = left;x<=right;x++){
                    for(int y = top;y<=bottom;y++){
                        count++;
                        sum+=img[x][y];
                    }
                }
                result[i][j] = sum/count;
            }
        }
        return result;
    }
}
